package com.qianyu.project.service.smj;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qianyu.project.core.annotation.FlowBegin;
import com.qianyu.project.core.annotation.FlowEntry;
import com.qianyu.project.entity.ApplyLaborPayment;
import com.qianyu.project.mapper.provider.smj.smjLaberApplyDao;
import com.qianyu.project.utils.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Map;

@Service
public class smjLaberApplyServiceImpl implements smjLaberApplyService {
    @Autowired
    private smjLaberApplyDao lad;

    @Override//添加劳务付款
    public String AddLaberApply(String apply_date, String payment_name, String type, String ctr_id, String p_id, String company_id, String contract_amount, String penalty, String withhold, String settle_type, String bank_id, String agree_amount, String handler_id, String agree_upper, String attach_ids, String settle_comment) {
        String update_date = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        String[] ids = update_date.split(" ");
        String ids1 =ids[0];
        String ids2 =ids[1];
        String[] ids3 = ids1.split("-");
        String[] ids4 = ids2.split(":");
        String id ="";
        for (int i = 0; i <ids3.length ; i++) {
            id += ids3[i];
        }
        for (int i = 0; i <ids4.length ; i++) {
            id += ids4[i];
        }
        lad.AddLaberApply( id,apply_date, payment_name, type, ctr_id, p_id, company_id, contract_amount, penalty, withhold, settle_type, bank_id, agree_amount, handler_id, agree_upper, attach_ids, settle_comment);
        return id;
    }

    @FlowBegin("apply_labor_payment")//发起审批
    @Override
    public Integer FlowLaberApply(@FlowEntry("id") ApplyLaborPayment applyLaborPayment) {
        lad.UpdateApproveStatus(1, applyLaborPayment.getId());
        return 1;
    }

    @Override//查看劳务付款列表
    public IPage<Map<String, Object>> listLaberApply(Map<String, String> params) {
        IPage<Map<String, Object>> page= PageUtil.createPage(params);
        return lad.listLaberApply(page,params);
    }

    @Override//获取审批流程
    public List<Map<String, Object>> getfromaudit(String id) {
        String fid = lad.getFid(id);
        return lad.getfromaudit(fid);
    }
}
